var app = getApp();
Page(Object.assign({}, {
    data:{
        inited : false,
        form : {},
        type : 'shop',
        tid : 0,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onLoad:function(options){
        var self = this;

        if( options.scene ){
            var list = options.scene.split('_');
            options.type = list[0] ? list[0] : 0;
            options.tid = list[1] ? list[1] : 0;
        }
        self.setData({
            type : options.type ? options.type : '',
            tid : options.tid > 0 ? options.tid : 0,
        })

        app.com.auth(function(user){
            app.com.http('admin','POST',{op:'drawinit',frm:'addshopmoney'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        params : res.data.data.params,
                        inited : true,
                    });

                    wx.setNavigationBarTitle({
                        title:  '充值',
                    });
                    
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },self);
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.sharedata.title,
            path: '',
        }
    },
    addthis : function(e){
        this.setData({
            money : e.currentTarget.dataset.m
        })
    },
    confirm(e){
        var self = this;
        
        if( self.data.money*1 <= 0 || !self.data.money ) {
            app.com.toast('请填写充值金额');
            return false;
        }
        
        var postdata = {
            op:'payadd',
            money : self.data.money,
            type : self.data.type,
            tid : self.data.tid,
        };

        if( self.data.payed ) return false;
        self.data.payed = true;

        app.com.http('admin','POST',postdata,0,true,'','',function(res){
            if (!res.data.errno && res.data) {
                
                wx.requestPayment({
					'appId' : res.data.data.appId,
                    'timeStamp': res.data.data.timeStamp,
                    'nonceStr': res.data.data.nonceStr,
                    'package': res.data.data.package,
                    'signType': 'MD5',
                    'paySign': res.data.data.paySign,
                    'success': function (payres) {
                        if( payres.errMsg == 'requestPayment:ok' ){
                            app.com.toast('支付完成');
                            wx.navigateBack();
                        }
                    },
                    'fail': function (payres) {
                        
                    }
                });
                self.data.payed = false;
            }else{
                app.com.alert(res.data.message);
            }
            self.data.payed = false;
        });
        
    },
    money : function(e){
        this.setData({
            money : e.detail.value
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },
}))